<template>
  <div class="right-wrap">
    <div class="issues-field-list">
      <div class="issues-field">
        <div class="issues-field__label">影像质量评估</div>
        <div class="issues-field__content">
          <el-select v-model="form.pass" style="width: 100%">
            <el-option
              v-for="item in state.passOptions"
              :key="item.code"
              :label="item.value"
              :value="item.code"
            />
          </el-select>
        </div>
      </div>

      <div class="issues-field">
        <div class="issues-field__label">开始日期 - 截止日期</div>
        <div class="issues-field__content">
          <el-date-picker
            v-model="state.dateRange"
            type="daterange"
            :disabled="!canEdit"
            start-placeholder="开始日期"
            end-placeholder="截止日期"
            value-format="YYYY-MM-DD"
          />
        </div>
      </div>

      <div class="issues-field">
        <div class="issues-field__label">优先级</div>
        <div class="issues-field__content">
          <el-select v-model="form.priority" style="width: 100%" :disabled="!canEdit">
            <el-option
              v-for="item in state.priorityOptions"
              :key="item.code"
              :label="item.value"
              :value="item.code"
            />
          </el-select>
        </div>
      </div>
    </div>

    <div class="issues-participates">
      <div class="title">
        参与者
        <span>（2）</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, reactive, watch } from 'vue'

import { codeMaps, getByDictCodeList } from '@/api/backend/dict'
import { getToday } from '@/api/help'

// import { Edit } from '@element-plus/icons'
// import FilterPopper from '../components/FilterPopper.vue'
import IBaseObj from '#/index'
// import { useState } from './issuesState'

// const { form, canEdit } = useState()

defineProps({
  info: {
    type: Object,
    default: () => {},
  },
})

const state: IBaseObj = reactive({
  dateRange: '',
  passOptions: [],
  priorityOptions: [],
})

watch(
  () => state.dateRange,
  (val) => {
    const [startDate, endDate] = val
    form.value.beginTime = startDate || ''
    form.value.endTime = endDate || ''
  }
)

watch(
  () => form.value.pass,
  (val: number | string) => {
    // 102700 - 不符合才能编辑
    canEdit.value = val === 102700
  }
)

const getDictData = async () => {
  const ret = await getByDictCodeList([codeMaps.pass, codeMaps.priority])
  state.passOptions = ret[codeMaps.pass]
  state.priorityOptions = ret[codeMaps.priority]
  form.value.priority = state.priorityOptions[0]?.code
}

const getTodayTime = async () => {
  const ret = await getToday()
  state.dateRange = [new Date(ret.data)]
}
getTodayTime()
getDictData()
</script>

<style lang="scss" scoped>
.issues-field {
  & + & {
    margin-top: 20px;
  }

  cursor: pointer;

  &__label {
    margin-bottom: 10px;
    font-weight: bold;
  }

  &__content {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

.issues {
  &-participates {
    margin-top: 62px;
    margin-bottom: 8px;

    .title {
      font-weight: bold;
    }
  }
}
</style>
